begintownscript;

variables;
short pc_counter = 0;
short choice = 0;

body;

beginstate 0; // INIT_STATE
	set_level(6, 70);
	set_level(7, 70); 
	set_name(8, "Brook");
	set_name(12, "Brother Hemlock");
	enable_add_chars(1);
	set_crime_tolerance(2);

	//FINAL SPIEL SETUP
	if(get_flag(11,10) == 1){
		force_view_center(12,20);
		force_instant_terrain_redraw();
		activate_hidden_group(10);
		relocate_character(0,12,22);
		relocate_character(1,13,22);
		relocate_character(2,12,23);
		relocate_character(3,13,23);
		set_character_facing(1000,0);
		force_instant_terrain_redraw();
		message_dialog("You cautiously open your eyes, desperately hoping that you don't see any lizards, drakes, hydras, newts, salamanders, or dragons. Luckily, you've reappeared in the Order of Krell's temple, in what appears to be Ephesos's quarters.","Ephesos calmly begins to speak.");
		set_state_continue(40);
		}
break;

beginstate 1; // EXIT_STATE

break;

beginstate 2; // START_STATE

break;

beginstate 10;
	set_total_visibility(0);
break;

beginstate 11;
	move_to_new_town(3,17,8);
break;

beginstate 12;
	move_to_new_town(3,10,21);
break;

beginstate 13;
	move_to_new_town(3,11,35);
break;

beginstate 14;
	move_to_new_town(3,26,40);
break;

beginstate 15;
	move_to_new_town(3,37,39);
break;

beginstate 16;
	move_to_new_town(3,39,30);
break;

beginstate 17;
	move_to_new_town(3,39,18);
break;

beginstate 19; //Walk out into the treetops for the 1st time
	if (get_flag(4,0) != 1) {
		reset_dialog();
		add_dialog_str(0, "You step out onto the walkways of the upper Temple, and are stunned by what you see.", 0);
		add_dialog_str(1, "The buildings up here have been worked flawlessly into the treetops, and they're all connected by impressively made rope bridges.", 0);
		add_dialog_str(2, "However, what amazes you most is that the treetops seem to be filled with small, blue, glowing flowers. You decide to ask Brother Elm about this when you see him next.",0);
		run_dialog(1);
		set_flag(4,0,1);
		}
break;

beginstate 20; //healing in inn room
	reset_dialog();
	add_dialog_str(0, "Much of the Order's quarters are incredibly comfortable, and this room is no exception. If you chose, you could sleep for a few hours and recharge a bit...", 0);
	add_dialog_choice(0, "Leave.");
	add_dialog_choice(1, "Rest for a while.");
	choice = run_dialog(1);
	pc_counter = 0;
	if (choice == 2) {
		play_sound(20);
		message_dialog("You take a quick nap, and wake up refreshed and ready to fight for the Order.","");
		while (pc_counter <= 5) {
			if (char_ok(pc_counter) == 1) {
				change_char_energy(pc_counter, 200);
				change_char_health(pc_counter, 200);
				}
			pc_counter = pc_counter + 1;
			}
		set_ticks_forward(625);
		pc_counter = 0;
		}
	else {
		message_dialog("You leave the room undisturbed for the next person to use it.","");
		block_entry(1);
		}
break;

beginstate 21; //Block entry to Ephesos's quarters
	message_dialog("As you part the curtains to this room, a disembodied voice begins to speak.","_I'm sorry, but Brother Ephesos isn't available right now. Please leave his quarters immediately._");
	block_entry(1);
break;

beginstate 40; //FINAL SPIEL
	pause(5);
	text_bubble_on_char(14, "We are forever in your debt.");
	force_instant_terrain_redraw();
	pause(20);
	erase_text_bubbles();
	text_bubble_on_char(14, "I do not know how");
	force_instant_terrain_redraw();
	pause(20);
	erase_text_bubbles();
	text_bubble_on_char(14, "we could ever repay you.");
	force_instant_terrain_redraw();
	pause(20);
	erase_text_bubbles();
	force_instant_terrain_redraw();
	pause(5);
	text_bubble_on_char(random_group_member(0), "Well...");
	force_instant_terrain_redraw();
	pause(15);
	activate_hidden_group(15);
	put_boom_on_space(14,20,2,0);
	run_animation_sound(95);
	force_instant_terrain_redraw();
	message_dialog("Brother Oakleaf appears out of nowhere, looking even angrier than before he freed Ephesos. The bottom of his robe is partially charred, and he appears to be out of breath.","");
	pause(5);
	erase_text_bubbles();
	text_bubble_on_char(15, "*cough*  *cough*");
	force_instant_terrain_redraw();
	pause(15);
	erase_text_bubbles();
	text_bubble_on_char(15, "Kharprev's army is coming!");
	force_instant_terrain_redraw();
	pause(20);
	erase_text_bubbles();
	text_bubble_on_char(15, "We must prepare ourselves!");
	force_instant_terrain_redraw();
	pause(20);
	set_character_facing(14,6);
	erase_text_bubbles();
	force_instant_terrain_redraw();
	pause(5);
	text_bubble_on_char(14, "Go tell Trechord.");
	force_instant_terrain_redraw();
	pause(15);
	erase_text_bubbles();
	text_bubble_on_char(14, "We'll be ready.");
	force_instant_terrain_redraw();
	pause(20);
	erase_text_bubbles();
	force_instant_terrain_redraw();
	pause(5);
	text_bubble_on_char(15, "I shall not fail, Ephesos.");
	force_instant_terrain_redraw();
	pause(15);
	set_character_pose(15,1);
	force_instant_terrain_redraw();
	pause(5);
	put_boom_on_char(15,2,0);
	run_animation_sound(95);
	erase_char(15);
	force_instant_terrain_redraw();
	pause(10);
	set_character_facing(14,4);
	force_instant_terrain_redraw();
	pause(5);
	erase_text_bubbles();
	text_bubble_on_char(14, "As you can see, we have");
	force_instant_terrain_redraw();
	pause(20);
	erase_text_bubbles();
	text_bubble_on_char(14, "a small lizard problem now.");
	force_instant_terrain_redraw();
	pause(20);
	erase_text_bubbles();
	text_bubble_on_char(14, "If you wish to stay here,");
	force_instant_terrain_redraw();
	pause(20);
	erase_text_bubbles();
	text_bubble_on_char(14, "you are free to help us");
	force_instant_terrain_redraw();
	pause(20);
	erase_text_bubbles();
	text_bubble_on_char(14, "defend our temple.");
	force_instant_terrain_redraw();
	pause(20);
	erase_text_bubbles();
	text_bubble_on_char(14, "However, we cannot ask any more");
	force_instant_terrain_redraw();
	pause(20);
	erase_text_bubbles();
	text_bubble_on_char(14, "of you than we already have.");
	force_instant_terrain_redraw();
	pause(20);
	erase_text_bubbles();
	text_bubble_on_char(14, "Just remember that wherever you go,");
	force_instant_terrain_redraw();
	pause(20);
	erase_text_bubbles();
	text_bubble_on_char(14, "you have our Order's blessing.");
	force_instant_terrain_redraw();
	pause(20);
	reset_dialog();
	add_dialog_str(0, "Ephesos serenely leaves the room, probably off to help prepare the troops for battle. You are left in the room alone.",0);
	add_dialog_str(1, "You can't help but think of how strange this mission has been. You've killed lizards, _distracted_ a dragon, and wound up sitting in a tree.",0);
	add_dialog_str(2, "While you're not sure whether or not you really want to face down an army of lizards, you can't help but think that you'd be in good hands.",0);
	add_dialog_str(3, "Regardless of the approaching army, you know this: your mission is accomplished. What happens next should be interesting...",0);
	run_dialog(1);
	erase_char(14);
	force_instant_terrain_redraw();
	end_scenario(1);
break;